/*
 * Copyright 2010 Mark Eschbach.
 *
 * $HeadURL$
 * $Id$
 */
package com.meschbach.cise.jam;

import com.meschbach.cise.util.StreamCopier;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;

/**
 *
 * @author "Mark Eschbach" &lt;meschbach@gmail.com&gt;
 */
public class CopyVisitor implements EntryVisitor {

    private static final CopyVisitor SHARED_INSTANCE = new CopyVisitor();

    public static CopyVisitor getSharedInstance() {
        return SHARED_INSTANCE;
    }

    public void visitEntry(String name, ZipEntry sourceEntry, ZipInputStream input, ZipOutputStream output) throws IOException {
        /*
         * Configure ther esulting entry and write it
         */
        ZipEntry resultingEntry = new ZipEntry(sourceEntry.getName());
        resultingEntry.setComment(sourceEntry.getComment());
        resultingEntry.setTime(sourceEntry.getTime());
        output.putNextEntry(resultingEntry);
        /*
         * Copy the contents
         */
        StreamCopier sc = new StreamCopier(input, output);
        sc.doCopy();
        /*
         * Close our entry
         */
        output.closeEntry();
    }
}
